package com.atguigu.tingshu.search.api;

import com.atguigu.tingshu.common.result.Result;
import com.atguigu.tingshu.model.album.AlbumInfo;
import com.atguigu.tingshu.model.search.AlbumInfoIndex;
import com.atguigu.tingshu.search.service.SearchService;
import com.google.common.annotations.GwtCompatible;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@Tag(name = "搜索专辑管理")
@RestController
@RequestMapping("api/search")
@SuppressWarnings({"all"})
public class SearchApiController {

    @Autowired
    private SearchService searchService;



    /**
     * 获取Redis中不同分类下不同排序方式-专辑排行榜
     *
     * @param category1Id
     * @param dimension
     * @return
     */
    @Operation(summary = "获取Redis中不同分类下不同排序方式-专辑排行榜")
    @GetMapping("/albumInfo/findRankingList/{category1Id}/{dimension}")
    public Result<List<AlbumInfoIndex>> getRankingList(@PathVariable Long category1Id, @PathVariable String dimension) {
        List<AlbumInfoIndex> list = searchService.getRankingList(category1Id, dimension);
        return Result.ok(list);
    }
    /**
     * /api/search/albumInfo/updateLatelyAlbumRanking
     * 更新所有分类下排行榜-手动调用
     */
    @Operation(summary = "更新所有分类下排行榜——手动调用")
    @GetMapping("/albumInfo/updateLatelyAlbumRanking")
    public Result updateLatelyAlbumRanking() {
        searchService.updateLatelyAlbumRanking();
        return Result.ok();
    }

    /**
     * /api/search/albumInfo/upperAlbum/{albumId}
     * 上架专辑
     */
    @Operation(summary = "上架专辑")
    @GetMapping("/albumInfo/upperAlbum/{albumId}")
    public Result upperAlbum(@PathVariable Long albumId) {
        //调用业务层方法
        searchService.upperAlbum(albumId);
        return Result.ok();
    }

    /**
     * /api/search/albumInfo/lowerAlbum/{albumId}
     * 下架专辑
     */
    @Operation(summary = "下架专辑")
    @GetMapping("/albumInfo/lowerAlbum/{albumId}")
    public Result lowerAlbum(@PathVariable Long albumId) {
        //调用业务层
        searchService.lowerAlbum(albumId);
        return Result.ok();
    }

    /**
     * 查询首页每个三级分类下热门专辑列表
     *
     * @param category1Id
     * @return
     */
    @Operation(summary = "查询首页每个三级分类下热门专辑列表")
    @GetMapping("/albumInfo/channel/{category1Id}")
    public Result<List<Map<String, Object>>> getCategory3Top6Hot(@PathVariable Long category1Id) {
        List<Map<String, Object>> list = searchService.getCategory3Top6Hot(category1Id);
        return Result.ok(list);
    }


    /**
     * 关键字自动补全
     *
     * @param keyword
     * @return
     */
    @Operation(summary = "关键字自动补全")
    @GetMapping("/albumInfo/completeSuggest/{keyword}")
    public Result<List<String>> completeSuggest(@PathVariable String keyword) {
        List<String> list = searchService.completeSuggest(keyword);
        return Result.ok(list);
    }


}

